package com.aspose.cells;

abstract class zabx {
   public static double a(double var0) {
      double[] var10 = new double[]{76.18009172947146D, -86.50532032941678D, 24.01409824083091D, -1.231739572450155D, 0.001208650973866179D, -5.395239384953E-6D};
      double var4 = var0;
      double var8 = var0 + 5.5D;
      var8 -= (var0 + 0.5D) * Math.log(var8);
      double var6 = 1.000000000190015D;

      for(int var11 = 0; var11 <= 5; ++var11) {
         var6 += var10[var11] / ++var4;
      }

      return -var8 + Math.log(2.5066282746310007D * var6 / var0);
   }

   public static double b(double var0) {
      if (var0 > 0.0D) {
         return Math.exp(a(var0));
      } else {
         double var2 = 1.0D - var0;
         double var4 = Math.sin(3.141592653589793D * var2);
         return zape.a(0.0D, var4) ? Double.NaN : 3.141592653589793D / (var4 * Math.exp(a(var2)));
      }
   }

   public static double a(double var0, double var2) {
      short var4 = 1000;
      double var5 = zape.a;
      double var7 = Double.MIN_VALUE / var5;
      if (var0 >= 0.0D && var2 >= 0.0D) {
         double var9 = a(var0);
         double var11;
         double var13;
         double var15;
         if (var2 >= var0 + 1.0D) {
            var11 = var2 + 1.0D - var0;
            var13 = 1.0D / var7;
            var15 = 1.0D / var11;
            double var24 = var15;

            for(int var19 = 1; var19 <= var4; ++var19) {
               double var20 = (double)(-var19) * ((double)var19 - var0);
               var11 += 2.0D;
               var15 = var20 * var15 + var11;
               if (Math.abs(var15) < var7) {
                  var15 = var7;
               }

               var13 = var11 + var20 / var13;
               if (Math.abs(var13) < var7) {
                  var13 = var7;
               }

               var15 = 1.0D / var15;
               double var22 = var15 * var13;
               var24 *= var22;
               if (Math.abs(var22 - 1.0D) <= var5 || var19 == var4 - 1) {
                  return 1.0D - Math.exp(-var2 + var0 * Math.log(var2) - var9) * var24;
               }
            }
         } else {
            if (var2 <= 0.0D) {
               return 0.0D;
            }

            var11 = var0;
            var15 = var13 = 1.0D / var0;

            for(int var17 = 0; var17 < var4; ++var17) {
               ++var11;
               var13 *= var2 / var11;
               var15 += var13;
               if (Math.abs(var13) < Math.abs(var15) * var5 || var17 == var4 - 1) {
                  return var15 * Math.exp(-var2 + var0 * Math.log(var2) - var9);
               }
            }
         }

         throw new IllegalArgumentException("GammaRegularized: ArgumentTooLargeForIterationLimit");
      } else {
         throw new IllegalArgumentException("Parameter name: GammaRegularized: " + var0 + " " + var2);
      }
   }

   static double a(double var0, double var2, double var4) {
      if (var0 < 0.0D) {
         return 0.0D;
      } else if (var0 == 0.0D) {
         return var2 == 1.0D ? 1.0D / var4 : 0.0D;
      } else if (var2 == 1.0D) {
         return Math.exp(-var0 / var4) / var4;
      } else {
         double var8 = a(var2);
         double var6 = Math.exp((var2 - 1.0D) * Math.log(var0 / var4) - var0 / var4 - var8) / var4;
         return var6;
      }
   }

   public static double b(double var0, double var2, double var4) {
      if (var0 == 1.0D) {
         var0 -= 1.0E-6D;
      } else if (var0 == 0.0D) {
         return 0.0D;
      }

      double var6;
      double var8;
      double var10;
      if (var0 < 0.05D) {
         var8 = Math.exp((a(var2) + Math.log(var0)) / var2);
         var6 = var8;
      } else if (var0 > 0.95D) {
         var8 = -com.aspose.cells.b.a.zq.a(1.0D - var0, 2.718281828459045D) + a(var2);
         var6 = var8;
      } else {
         var8 = zaby.d(var0);
         var10 = var8 < -0.5D * Math.sqrt(var2) ? var2 : Math.sqrt(var2) * var8 + var2;
         var6 = var10;
      }

      int var14 = 0;

      do {
         var10 = var0 - d(var6, var2, 1.0D);
         double var12 = a(var6, var2, 1.0D);
         if (var10 == 0.0D || var14++ > 64) {
            break;
         }

         var8 = var10 / Math.max(2.0D * Math.abs(var10 / var6), var12);
         double var17 = -((var2 - 1.0D) / var6 - 1.0D) * var8 * var8 / 4.0D;
         double var19 = var8;
         if (Math.abs(var17) < 0.5D * Math.abs(var8)) {
            var19 = var8 + var17;
         }

         if (var6 + var19 > 0.0D) {
            var6 += var19;
         } else {
            var6 /= 2.0D;
         }
      } while(Math.abs(var8) > 1.0E-10D * var6);

      if (Math.abs(var10) > 1.0E-10D * var0) {
         com.aspose.cells.a.c.zl.a("inverse failed to converge");
      }

      return var4 * var6;
   }

   static double c(double var0, double var2, double var4) {
      if (var0 <= 0.0D) {
         return 0.0D;
      } else {
         double var6 = 171.624376956302D;

         try {
            double var8 = var0 / var4;
            if (var8 > 1.0D) {
               double var10 = Math.log(Double.MAX_VALUE);
               return Math.log(var8) * (var2 - 1.0D) < var10 && var2 < var6 ? Math.pow(var8, var2 - 1.0D) * Math.exp(-var8) / var4 / b(var2) : Math.exp((var2 - 1.0D) * Math.log(var8) - var8 - Math.log(var4) - a(var2));
            } else {
               return var2 < var6 ? Math.pow(var8, var2 - 1.0D) * Math.exp(-var8) / var4 / b(var2) : Math.pow(var8, var2 - 1.0D) * Math.exp(-var8) / var4 / Math.exp(a(var2));
            }
         } catch (Exception var12) {
            return 0.0D;
         }
      }
   }

   public static double b(double var0, double var2) {
      if (var0 <= 0.0D) {
         return 0.0D;
      } else {
         try {
            return e(var2, var0 / 1.0D);
         } catch (Exception var5) {
            return 0.0D;
         }
      }
   }

   public static double d(double var0, double var2, double var4) {
      if (var0 <= 0.0D) {
         return 0.0D;
      } else {
         try {
            return e(var2, var0 / var4);
         } catch (Exception var7) {
            return 0.0D;
         }
      }
   }

   static double c(double var0, double var2) {
      double var4 = Double.MIN_VALUE;
      double var6 = 1.0D / var4;
      double var8 = 0.0D;
      double var10 = 0.0D;
      double var12 = 1.0D - var0;
      double var14 = var2 + 2.0D - var0;
      double var16 = 0.0D;
      double var18 = var2 + 1.0D;
      double var20 = 1.0D;
      double var22 = 1.0D;
      double var24 = var14 * var2;
      double var26 = var2;
      double var28 = var18 / var24;
      boolean var30 = false;
      double var31 = 0.0D;

      do {
         ++var8;
         ++var12;
         var10 = var12 * var8;
         var14 += 2.0D;
         var16 = var18 * var14 - var20 * var10;
         var22 = var24 * var14 - var26 * var10;
         if (var22 != 0.0D) {
            var31 = var16 / var22;
            var30 = Math.abs((var28 - var31) / var31) <= 0.0D;
            var28 = var31;
         }

         var20 = var18;
         var18 = var16;
         var26 = var24;
         var24 = var22;
         if (Math.abs(var16) > var6) {
            var20 *= var4;
            var18 = var16 * var4;
            var26 *= var4;
            var24 = var22 * var4;
         }
      } while(!var30 && var8 < 10000.0D);

      return !var30 ? 0.0D : var28;
   }

   static double d(double var0, double var2) {
      double var4 = var0;
      double var6 = 1.0D / var0;
      double var8 = var6;
      int var10 = 1;

      do {
         ++var4;
         var6 = var6 * var2 / var4;
         var8 += var6;
         ++var10;
      } while(var6 / var8 > 0.0D && var10 <= 10000);

      return var10 > 10000 ? 0.0D : var8;
   }

   static double e(double var0, double var2) {
      double var4 = var0 * Math.log(var2) - var2 - a(var0);
      double var6 = Math.exp(var4);
      return var2 > var0 + 1.0D ? 1.0D - var6 * c(var0, var2) : var6 * d(var0, var2);
   }
}
